package org.example.io.protocol.command;

import io.netty.channel.Channel;
import org.example.io.protocol.packet.MessageRequestPacket;
import org.example.io.util.LogUtil;
import org.example.io.util.LoginUtil;

import java.util.Scanner;

public class SendMessageCommand implements ConsoleCommand{
    @Override
    public void exec(Scanner scanner, Channel channel) {
        if (LoginUtil.hasLogin(channel)) {
            LogUtil.info("请输入对方用户名：");
            String toUsername = scanner.next();
            LogUtil.info("请输入消息内容：");
            String message = scanner.next();
            MessageRequestPacket packet = new MessageRequestPacket();
            packet.setToUsername(toUsername);
            packet.setMessage(message);
            channel.writeAndFlush(packet);
        } else {
            LogUtil.info("还未登录，请先登录");
        }
    }

    @Override
    public String commandType() {
        return "sendMessage";
    }
}
